import java.util.ArrayList;

public class BS {

	public static void main(String[] args) {
		StartGame start = new StartGame();
		ArrayList<Ship> ships = start.start();

		while (!ships.isEmpty()) {

			try {
				String guessInput = new Reading().read("Enter your guess");
				Coord guessCoord = posToCoord(guessInput);
				for (Ship ship:ships) {
					if (ship.getPos().contains(guessCoord)) {
						ship.getPos().remove(guessCoord);
						ship.setFlag((ship.getFlag()) + 1);
						System.out.println(ship.getFlag());
						if (ship.getFlag() == ship.getSize()) {
							System.out.println("guess " + guessCoord.getHor()
									+ " " + guessCoord.getVer() + " kill");

							break;
						}
						System.out.println("guess " + guessCoord.getHor() + " "
								+ guessCoord.getVer() + " hit");

					} else {
						// System.out.println("you're miss =(");
					}
				}
			} catch (NumberFormatException e) {
				System.out.println("Please enter integer value!");
			}

		}
		System.out.println("you're win!!!!");
		System.out.println("The end");
	}

	public static Coord posToCoord(String guess) {
		Coord coord = null;
		try {

			String hor = guess.substring(0, 1).toUpperCase();
			int ver = Integer.parseInt(guess.substring(1, guess.length()));
			int i = Letter.valueOf(hor).getValue();
			coord = new Coord(i, ver - 1);

		} catch (NumberFormatException e) {
			System.out
					.println("Please enter Your Guess format LetterNumber. For example, G3");
		}
		return coord;
	}
}
